package com.tangyee.home_exercise_diet.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.tangyee.home_exercise_diet.dao.FoodOrExerciseDbSchema.FoodOrExerciseTable;

public class FoodOrExerciseDbHelper extends SQLiteOpenHelper {


    // 数据库版本
    private static final int VERSION = 1;
    // 数据库名字
    private static final String DATABASE_NAME = "food_or_exercise_records.db";

    /**
     * 构造方法
     * @param context
     */
    public FoodOrExerciseDbHelper(Context context){
        super(context, DATABASE_NAME, null, VERSION);
    }

    /**
     * 根据Schema（协议）创建数据库
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + FoodOrExerciseTable.NAME + "(" +
                " _id integer primary key autoincrement,        " + // 主键
                FoodOrExerciseTable.Cloumns.DATE                  + ", " +
                FoodOrExerciseTable.Cloumns.TYPE                  + ", " +
                FoodOrExerciseTable.Cloumns.NAME                  + ", " +
                FoodOrExerciseTable.Cloumns.PER_UNIT_CALORIE      + ", " +
                FoodOrExerciseTable.Cloumns.UNIT                  + ", " +
                FoodOrExerciseTable.Cloumns.AMOUNT                + ", " +
                FoodOrExerciseTable.Cloumns.IMAGE                 +
                ")"
        );
    }

    /**
     * 更新数据库
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
